package com.bolt.admin.module.quartz.dto.converter;

import com.bolt.admin.module.quartz.dto.JobLogDTO;
import com.bolt.admin.module.quartz.entity.JobLogEntity;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * Created by Administrator on 2018/11/27.
 */
public class JobLogConverter {
    private JobLogConverter() {
// do nothing
    }

    /**
     * Entity对象转换为DTO对象
     *
     * @param log DO对象
     * @return DTO对象
     */
    public static JobLogDTO toDTO(JobLogEntity log) {
        if (Objects.isNull(log)) {
            return null;
        }
        JobLogDTO result = new JobLogDTO();
        result.setId(log.getId());
        result.setBeanName(log.getBeanName());
        result.setCreateTime(log.getCreateTime());
        result.setCronExpression(log.getCronExpression());
        result.setExceptionDetail(log.getExceptionDetail());
        result.setIsSuccess(log.getIsSuccess());
        result.setJobName(log.getJobName());
        result.setMethodName(log.getMethodName());
        result.setParams(log.getParams());
        result.setTime(log.getTime());
        result.setFireTime(log.getFireTime());
        result.setPreviousFireTime(log.getPreviousFireTime());
        result.setNextFireTime(log.getNextFireTime());
        result.setFireCount(log.getFireCount());
        // TODO
        return result;
    }

    /**
     * DTO对象转换为Entity对象
     *
     * @param log DO对象
     * @return VO对象
     */
    public static JobLogEntity toEntity(JobLogDTO log) {
        if (Objects.isNull(log)) {
            return null;
        }
        JobLogEntity result = new JobLogEntity();
        result.setId(log.getId());
        result.setBeanName(log.getBeanName());
        result.setCreateTime(log.getCreateTime());
        result.setCronExpression(log.getCronExpression());
        result.setExceptionDetail(log.getExceptionDetail());
        result.setIsSuccess(log.getIsSuccess());
        result.setJobName(log.getJobName());
        result.setMethodName(log.getMethodName());
        result.setParams(log.getParams());
        result.setTime(log.getTime());
        result.setFireTime(log.getFireTime());
        result.setPreviousFireTime(log.getPreviousFireTime());
        result.setNextFireTime(log.getNextFireTime());
        result.setFireCount(log.getFireCount());
        // TODO
        return result;
    }

    /**
     * DTO对象转换为DO对象
     *
     * @param log DO对象
     * @return VO对象
     */
    public static JobLogEntity toEntity(JobLogEntity result, JobLogDTO log) {
        if (Objects.isNull(log)) {
            return null;
        }

        result.setBeanName(log.getBeanName());
        result.setCreateTime(log.getCreateTime());
        result.setCronExpression(log.getCronExpression());
        result.setExceptionDetail(log.getExceptionDetail());
        result.setIsSuccess(log.getIsSuccess());
        result.setJobName(log.getJobName());
        result.setMethodName(log.getMethodName());
        result.setParams(log.getParams());
        result.setTime(log.getTime());
        result.setFireTime(log.getFireTime());
        result.setPreviousFireTime(log.getPreviousFireTime());
        result.setNextFireTime(log.getNextFireTime());
        result.setFireCount(log.getFireCount());
// TODO
        return result;
    }

    /**
     * 批量 Entity对象转换为DTO对象
     *
     * @param logList Entity集合对象
     * @return DTO对象
     */
    public static List <JobLogDTO> toDTO(List <JobLogEntity> logList) {
        if (Objects.isNull(logList)) {
            return null;
        }
        return logList.stream().map(JobLogConverter::toDTO).collect(Collectors.toList());
    }

}
